// Copyright (c) 2023 CHANGLEI. All rights reserved.

/// Created by changlei on 2023/6/25.
///
/// 可描述的
abstract mixin class Describable {
  /// 可描述的
  String toDescribe([bool isTight = false]);

  @override
  String toString() => toDescribe(true);
}

/// 可描述的
extension DescribableObject on Iterable<Describable> {
  /// 可描述的
  String toDescribe([bool isTight = false]) => map((e) => e.toDescribe(isTight)).join();
}

/// 收紧
extension DescribeTightRange on Describable {
  /// 收紧
  (int, int) toTightRange([bool isTight = false]) {
    final string = toDescribe(isTight);
    if (isTight) {
      return (0, string.length);
    } else {
      final describe = toDescribe();
      final start = describe.indexOf(string);
      return (start, start + string.length);
    }
  }
}
